package com.javasm.springmybatis.timer;

import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.mail.SimpleMailMessage;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.TimeUnit;

/**
 * @Author：xieyunfan
 * @Version：1.0
 * @Date：2021/12/30-20:48
 * @Since:jdk1.8
 * @Description:
 */
public class TimerTest {
    public static void main(String[] args) throws ParseException {
        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                String name = Thread.currentThread().getName();
                System.out.println(name);
                System.out.println("你好世界");
            }
        };

        Date date = new Date();


        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String str="2021-12-30 21:47:30";
        Date parse = simpleDateFormat.parse(str);
        timer.schedule(timerTask,parse);

//        timer.schedule(timerTask,1000,0);

        System.out.println("你好");

        //延迟执行
//        try {
//            TimeUnit.SECONDS.sleep(50);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }


        //后面的方法直接会执行
//        timer.cancel();



    }
}
